package com.promote.algorithm;

/**
 * @ClassName RemoveDuplicates
 * Description 删除排序数组中的重复项
 * @Author LiZiHao
 * Date 2022/3/3 10:22
 * @Version 1.0
 **/
public class RemoveDuplicates {

    public int removeDuplicates(int[] nums) {
        int n = nums.length;

        if (n == 0) {
            return 0;
        }

        int fast = 1, slow = 1;
        while (fast < n) {
            if (nums[fast] != nums[fast - 1]) {
                nums[slow] = nums[fast];

                ++slow;
            }
            ++fast;
        }
        return slow;
    }
}
